<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<style>
  .tool-bar {
    position: fixed;
    right: 0%;
    top: 30%;
    display: flex;
    align-items: center;
    flex-direction: column;
    align-items: center;
    width: 35px;
  }
  .item {
    position: relative;
    width: 35px;
    height: 35px;
    background-color: #7a6e6e;
    margin-bottom: 1px;
    cursor: default;
    border-radius: 3px 0 0 3px;
  }
  .icon {
    display: inline-block;
    width: 100%;
    height: 100%; 
    background-image: url(/img/toolbars.png);
    pointer-events: none;
  }
  .name {
    position: absolute;
      z-index: -1;
      right: 35px;
      top: 0;
      
      width: 0;
      height: 35px;
      line-height: 35px;

      color: #fff;
      text-align: center;
      font-size: 12px;
      background-color: #7a6e6e;
      /* cursor: pointer; */
      border-radius: 3px 0 0 3px;
      transition: width .2s ease;
  }
  .item:hover,
  .item:hover .name {
      background-color: #cd1926;
    }
</style>
<body>
  <div class="tool-bar">
    <div class="item">
      <i class="icon"></i>
      <div class="name">购物车</div>
    </div>
    <div class="item">
      <i class="icon"></i>
      <div class="name">收藏</div>
    </div>
    <div class="item">
      <i class="icon"></i>
      <div class="name">限时活动</div> 
    </div>
    <div class="item">
      <i class="icon"></i>
      <div class="name">大礼包</div>
    </div>
    <script>
      var iconEls = document.querySelectorAll(".icon")
      var toolBarEl = document.querySelector(".tool-bar")
      var itemEls = document.querySelectorAll(".item")
      for (var i = 0; i < iconEls.length; i++) {
      var iconEl = iconEls[i]
      iconEl.style.backgroundPosition = `-48px -${i*50}px`
      }
    for (var itemEl of itemEls) {
      itemEl.onmouseenter = function() {
        var nameEl = this.children[1]
        nameEl.style.width = "62px"
      }
      itemEl.onmouseleave = function() {
        var nameEl = this.children[1]
        nameEl.style.width = "0"
      }
    }
    
    // toolBarEl.onmouseover = function(event) {
    //   var iconEl = event.target
    //   var nameEl = iconEl.nextElementSibling
    //   nameEl.style.width = "62px"
    // }
    // toolBarEl.onmouseout = function(event) {
    //   var iconEl = event.target
    //   var nameEl = iconEl.nextElementSibling
    //   nameEl.style.width = "0"
    // }
    </script>
  </div>
</body>
</html>